<?php

class Dangkyhoc extends MY_Admin
{
	// Protected or private properties
	protected $_template;
	
	// Constructor
	public function __construct()
	{
		parent::__construct();

		// Check if the logged user is an administrator
		//$this->access_library->check_access();
		// Load needed models, libraries, helpers and language files
		$this->load->module_model('admin', 'dangkyhoc_model', 'dangkyhoc');
		$this->load->module_language('admin', 'general');
		$this->load->module_language('admin', 'dangkyhoc');
		$this->user = $this->access->get_user();
		$this->load->helper('url'); 
		//You should autoload this one ;)
		//$this->access->restrict('Admin.Hocvien.Index');
		//$this->access->restrict();
	}

	// Public methods
	public function index() 
	{
		$this->access->restrict('Admin.Dangkyhoc.Index');
		
		$data['ItemID'] = 'User';
		$data['title'] = 'Danh sách Sinh viên';		
		
		$this->load->library('basic_library');
		$this->load->library('pagination');
		$this->load->helper('url');
		$config = array();
		$config['base_url'] 	= base_url().'admin/dangkyhoc/';
		$config['total_rows'] 	= $this->dangkyhoc->count_all_dangky();
		$config['per_page'] 	= 100;
		$config['uri_segment']	= 3;
		$config['num_links'] = 5;
		$config['first_link'] = 'Đầu tiên';
        $config['last_link'] = 'Cuối cùng';
        $config['next_link'] = 'Tiếp theo';
        $config['prev_link'] = 'Lùi lại';
		$this->pagination->initialize($config);
		$page = ($this->uri->segment(3))? $this->uri->segment(3):0;
		
		$data['hocviens'] 	= $this->dangkyhoc->get_all_dangky($config['per_page'], $page);
		$data['lops'] 		= $this->dangkyhoc->get_tenlop();
		$data['links'] 		= $this->pagination->create_links();		
		
		$this->_template['page']	= 'dangkyhoc/list';
		$this->system_library->load($this->_template['page'], $data, TRUE);
	}
	
	public function search()
	{
		$data['ItemID'] = 'User';
		$data['title'] = 'Tìm kiếm thông tin';
		$data['search_keyword'] = trim($this->input->post('keyword', TRUE));
		if($data['search_keyword']!=='')
		{
			$data['result'] = $this->hocvien->search_data($data['search_keyword']);
			$this->_template['page']	= 'hocvien/result';
			$this->system_library->load($this->_template['page'], $data, TRUE);
		}
		else
		{
			redirect('admin/hocvien', 'refresh');
		}
	}
	
	public function delete($id)
	{
		//$this->access->restrict('Admin.Dangkyhoc.Delete');
		$this->dangkyhoc->delete_dangky($id);
		$this->session->set_flashdata('message', lang('successfully_deleted'));
		redirect('admin/dangkyhoc', 'refresh');
	}
	
	public function enable($id = null)
	{
		if ($id == null)
		{
			$id = $this->input->post('id');
		}
			
		$this->hocvien->change_status_hocvien($id,1);
		redirect('admin/hocvien', 'refresh');
		
	}
	public function disable($id = null)
	{
		if ($id == null)
		{
			$id = $this->input->post('id');
		}
			
		$this->hocvien->change_status_hocvien($id,0);
		redirect('admin/hocvien', 'refresh');
	}
}

/* End of file jobs.php */